/**
 * 应用类型定义
 */
export interface App {
  id: number;
  name: string;
  description: string;
  icon: string;
  categoryId: number;
  isFeatured: boolean;
  version?: string;
  developerId?: number;
  developerName?: string;
  status?: number; // 0待审核 1已发布 2已下架
  config?: AppConfig;
  component?: string; // 组件名称，用于本地组件渲染
  storagePath?: string;
  views?: number;
  screenshots?: string[]; // 应用截图
  createdAt?: string;
  updatedAt?: string;
}

/**
 * 应用配置
 */
export interface AppConfig {
  window?: {
    width: number;
    height: number;
    resizable?: boolean;
    maximizable?: boolean;
    minimizable?: boolean;
  };
  permissions?: string[];
}

/**
 * 应用分类
 */
export interface AppCategory {
  id: number;
  name: string;
  code: string;
  description?: string;
  icon?: string;
  sort?: number;
  status?: number;
}

/**
 * 应用窗口
 */
export interface AppWindow {
  id: string;
  appId: number;
  title: string;
  icon?: string;
  url?: string;
  component?: string; // 组件名称，用于本地组件渲染
  x: number;
  y: number;
  width: number;
  height: number;
  minWidth?: number;
  minHeight?: number;
  isActive: boolean;
  isMaximized: boolean;
  isMinimized: boolean;
  resizable?: boolean;
  maximizable?: boolean;
  minimizable?: boolean;
  zIndex: number;
  originalState?: {
    x: number;
    y: number;
    width: number;
    height: number;
  };
}

/**
 * 应用窗口配置
 */
export interface AppWindowConfig {
  width: number;
  height: number;
  minWidth?: number;
  minHeight?: number;
  resizable?: boolean;
  maximizable?: boolean;
  minimizable?: boolean;
}

/**
 * 应用状态常量
 */
export enum AppStatus {
  PENDING = 0,
  PUBLISHED = 1,
  UNPUBLISHED = 2
}

/**
 * 应用状态选项
 */
export const appStatusOptions = [
  { label: '待审核', value: AppStatus.PENDING },
  { label: '已发布', value: AppStatus.PUBLISHED },
  { label: '已下架', value: AppStatus.UNPUBLISHED }
];

/**
 * 应用信息接口
 */
export interface AppInfo {
  id: string;
  name: string;
  description: string;
  version: string;
  icon: string;
  developer: string;
  category: string;
  tags: string[];
  screenshots: string[];
  downloadCount: number;
  rating: number;
  status: 'published' | 'draft' | 'pending' | 'rejected';
  createdAt: string;
  updatedAt: string;
}

/**
 * 应用权限接口
 */
export interface AppPermission {
  id: string;
  name: string;
  description: string;
  key: string;
}

/**
 * 应用SDK接口
 */
export interface AppSDK {
  // 核心方法
  getAppInfo(): Promise<App>;
  getAppPermissions(): Promise<string[]>;
  
  // 窗口管理
  closeWindow(): void;
  minimizeWindow(): void;
  maximizeWindow(): void;
  restoreWindow(): void;
  
  // 数据存储
  getData(key: string): Promise<any>;
  setData(key: string, value: any): Promise<void>;
  removeData(key: string): Promise<void>;
  
  // 通知
  showNotification(title: string, options?: NotificationOptions): Promise<void>;
  
  // 系统集成
  openUrl(url: string): Promise<void>;
  copyToClipboard(text: string): Promise<void>;
  readFromClipboard(): Promise<string>;
  
  // 文件操作
  openFile(options?: { accept?: string }): Promise<File | null>;
  saveFile(content: Blob, filename: string): Promise<void>;
  
  // 通信
  sendMessage(targetAppId: string, message: any): Promise<void>;
  onMessage(callback: (message: any, sourceAppId: string) => void): () => void;
}

/**
 * 应用消息接口
 */
export interface AppMessage {
  type: string;
  payload: any;
  source: string;
  target: string;
  timestamp: number;
}

/**
 * 应用API请求接口
 */
export interface AppApiRequest {
  method: 'GET' | 'POST' | 'PUT' | 'DELETE';
  url: string;
  headers?: Record<string, string>;
  params?: Record<string, any>;
  data?: any;
}

/**
 * 应用API响应接口
 */
export interface AppApiResponse<T = any> {
  data: T;
  status: number;
  statusText: string;
  headers: Record<string, string>;
} 